<?php
/**
 * mediatype
 * 媒体类型
 * @author Administrator
 * @version
 */
class Model_Tables_Mediatype extends Zend_Db_Table_Abstract {
    /**
     * The default table name
     */
    protected $_name = 'mediatype';
    /**
     * add
     * 增加媒体类型
     * @param $params 字段信息
     */
    public function add( $params )
    {
        $data = array(
		'VMT_NAME' => $params['VMT_NAME'],
		'VMT_KEY' => $params['VMT_KEY'],
		'VMT_NAME_EN' => $params['VMT_NAME_EN'],
		'VMT_TYPE' => $params['VMT_TYPE'],
		'VMT_PROTOCOL' => $params['VMT_PROTOCOL'],
		'VMT_STREAM_TYPE' => $params['VMT_STREAM_TYPE'],
        );
        return $this->insert($data);
    }
    /**
     * modify
     * 编辑媒体类型
     * @param $params 字段信息
     * @param $VMT_ID 主键值
     */
    public function modify( $params, $VMT_ID )
    {
        $data = array(
		'VMT_NAME' => $params['VMT_NAME'],
		'VMT_KEY' => $params['VMT_KEY'],
		'VMT_NAME_EN' => $params['VMT_NAME_EN'],
		'VMT_TYPE' => $params['VMT_TYPE'],
		'VMT_PROTOCOL' => $params['VMT_PROTOCOL'],
		'VMT_STREAM_TYPE' => $params['VMT_STREAM_TYPE'],
        );
        $where = 'VMT_ID = '.$VMT_ID ;
        return $this->update($data , $where );
    }
    /**
     * modifyAjax
     * 无刷新编辑媒体类型
     * @param $VMT_ID 主键值
     * @param $field 字段
     * @param $value 值
     */
    public function modifyAjax( $VMT_ID, $field, $value )
    {
    	$db = $this->getAdapter();
    	$data = array($field => $value);
    	$where = $db->quoteInto("VMT_ID=?", $VMT_ID);
        return $this->update($data , $where );
    }
    /**
     * modifyAjaxRevers
     * 无刷新字段反转媒体类型
     * @param $field 需要反转的字段
     * @param $VMT_ID 主键值
     */
    public function modifyAjaxRevers( $field ,$pri)
    {
    	$db = $this->getAdapter();
    	$sql = "update mediatype set  $field =not  $field  where VMT_ID=' $pri'";
		return $db->query($sql);
    }
    /**
     * del
     * 根据条件删除媒体类型
     * @param $VMT_ID 主键值
     */
    public function del( $VMT_ID )
    {
     	$where = 'VMT_ID = '.$VMT_ID;
        return $this->delete($where);
    }
    /**
     * getInfo
     * 获取媒体类型信息
     * @param $VMT_ID 主键值
     * @return 结果数组
     */
    public function getInfo($VMT_ID)
    {
        $row = $this->fetchRow('VMT_ID = ' . $VMT_ID);
        if (!$row) {
        	return null;
        }
        else
        {
        	return $row->toArray();
        }
    }
    /**
     * getCount
     * 获取媒体类型数量
     * @param int  搜索条件
     * @return 结果数
     */
    public function getCount($s = "")
    { 
        $select = $this->select()->from($this->_name,'count(*) as num');
    	if($s!="")  
    	{
    		$db = $this->getAdapter();
			$where = $db->quoteInto("VMT_ID=?", $s);
    		$select = $select->where($where);
    	}
        $result = $this->fetchRow($select)->num;
        return $result;
    }
    /**
     * getList
     * 取媒体类型数据分页
     * @param int  页码
     * @param int  每页的行数 
     * @param  搜索条件
     * @return 行数组
     */
    public function getList($page, $numPerPage = 10,$s= "")
    {
    	$page = (1>$page) ? 1 : $page;
    	$offset = ($page-1)*$numPerPage;
        $orderby = array('VMT_ID');
        if($s!="")     
		{
			$db = $this->getAdapter();
			$where = $db->quoteInto("VMT_ID= ?", $s);
		}  
        $result = $this->fetchAll($where,$orderby, $numPerPage, $offset )->toArray();
        return $result;
    }
 	public function getMediaTypeList($model)
    {
        $db = $this->getAdapter();		
		$sql = "select VMT_ID, VMT_NAME from mediatype where VMT_TYPE=:model";
		$result = $db->query($sql,array("model"=>$model));
    	$types = array();
        if (!empty($result))
	        {
	            foreach ($result as $item)
	            {
	                $types[$item['VMT_ID']] = $item['VMT_NAME'];
	            }
	        }
        return $types;
    }
}
